package com.knife.lov.infra.aspect;

import com.knife.lov.domain.service.impl.KnifeLovValueHelper;
import com.knife.lov.infra.annotations.KnifeProcessLovValue;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Method;

/**
 * @author qiang.zhang Date 2021-11-13 10:31
 * <p>
 * 直接翻译 AOP 切面类，切入点是注解
 */
@Component
@Order(300)
public class KnifeLovProcessAdvice implements MethodInterceptor {
    @Resource
    private KnifeLovValueHelper knifeLovValueHelper;

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object result = invocation.proceed();
        Method method = invocation.getMethod();
        KnifeProcessLovValue annotation = method.getAnnotation(KnifeProcessLovValue.class);
        if (annotation != null) {
            knifeLovValueHelper.lovProcessTranslateWithClearCache(result);
        }
        return result;

    }
}
